package io.renren.modules.problem.controller;

import com.alibaba.fastjson.JSON;
import io.renren.common.annotation.SysLog;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.problem.entity.Problem;
import io.renren.modules.problem.service.ProblemService;
import io.renren.modules.sys.controller.AbstractController;
import io.swagger.annotations.Api;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(value = "问题管理-问题接口", tags = { "问题管理-问题接口" })
@RestController
@RequestMapping("/sys/problem")
public class ProblemController extends AbstractController {
    @Autowired
    ProblemService problemService;
    /**
     * 新增问题
     */
    @SysLog("保存问题")
    @PostMapping("/save")
    //@RequiresPermissions("sys:problem:save")
    public R save(@RequestBody Problem problem) {
        ValidatorUtils.validateEntity(problem);

        problemService.saveProblem(problem);
        Long[] roleIds={1l,2l,3l};
        String string = JSON.toJSONString(roleIds);
        System.err.println("string = " + string);
        return R.ok();
    }
    /**
     * 删除问题
     */
    @SysLog("删除问题")
    @PostMapping("/delete")
   // @RequiresPermissions("sys:problem:delete")
    public R delete(@RequestBody Long[] roleIds) {
        problemService.deleteBatch(roleIds);

        return R.ok();
    }
    /**
     * 修改问题
     */
    @SysLog("修改问题")
    @PostMapping("/update")
    //@RequiresPermissions("sys:problem:update")
    public R update(@RequestBody Problem problem) {
        ValidatorUtils.validateEntity(problem);
        problemService.update(problem);

        return R.ok();
    }
    /**
     * 问题列表进行分页处理
     */
    @GetMapping("/select")
   // @RequiresPermissions("sys:problem:select")
    public R select(@RequestParam Map<String, Object> params) {
        PageUtils page = problemService.queryPage(params);
        return R.ok().put("list", page);
    }


}
